using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
using WPFExcelReport.Helpers;
using WPFExcelReport.Controls;
namespace WPFExcelReport
{
    public partial class VVADBLATT
    {
        public void SetUpNewRow(ref DataRow dwReturn)
        {

            switch (app.company)
            {
                case "YGR":
                case "YCC":
                default:
                    #region
                    dwReturn["VADMANDANT"] = app.Mandant;
                    dwReturn["VADKOLL"] = "     ";
                    dwReturn["VADART"] = "                        ";
                    dwReturn["VADSPRKZ"] = " ";
                    dwReturn["VADARTBEZ"] = "                              ";
                    dwReturn["VADSTDTXT"] = "                    ";
                    dwReturn["VADPFCODE"] = "     ";
                    dwReturn["VADETG"] = " ";
                    dwReturn["VADSTDART"] = "          ";
                    dwReturn["VADSTDAUF1"] = " ";
                    dwReturn["VADSTDAUF2"] = " ";
                    dwReturn["VADSTDAUF3"] = " ";
                    dwReturn["VADFILLER"] = "                                  ";
                    dwReturn["VADAENDZL"] = "000";
                    dwReturn["VADAENDBEN"] = "        ";
                    dwReturn["VADAENDDAT"] = "0";
                    dwReturn["VADNEUBEN"] = "        ";
                    dwReturn["VADNEUDAT"] = "0";
                    #endregion
                    break;
                case "JLT":
                    break;
            }
        }
        public void InsertVADBLATT(DataRow dwData, string ITXDBVERSION = "50.24")
        {

            or1 = OracleDB.CreateCommand();
            switch (ITXDBVERSION)
            { 
                default:
                    or1.CommandText = "INSERT INTO VADBLATT "
                    + " SELECT :VADMANDANT:,:VADKOLL:,:VADART:,:VADSPRKZ:,:VADARTBEZ:,:VADSTDTXT:,:VADPFCODE:,:VADETG:,:VADSTDART:,:VADSTDAUF1:,:VADSTDAUF2:,:VADSTDAUF3:,:VADFILLER:,:VADAENDZL:,:VADAENDBEN:,:VADAENDDAT:,:VADNEUBEN:,:VADNEUDAT: FROM DUAL WHERE NOT EXISTS( SELECT 1 FROM VADBLATT WHERE VADMANDANT=:VADMANDANT: AND VADKOLL=:VADKOLL: AND VADART=:VADART:)";
                    or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
                    break;
            }
            Connect2Proxy(or1);
        }
        public DataSet QueryVADBLATT(DataRow dwData, int option = 1)
        {

            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM VADBLATT WHERE  ROWNUM<2 ";
                    break;
                case 1:
                    or1.CommandText = "SELECT * FROM VADBLATT  "
                    + " WHERE  VADMANDANT=:VADMANDANT: AND VADKOLL=:VADKOLL: AND VADART =:VADART:";
                    or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
                    break;
                case 99:
                    or1.CommandText = "SELECT * FROM VADBLATT  WHERE ROWNUM<50";
                    break;
                default:
                    break;
            }
            SResult = Connect2Proxy(or1);
            SResult.Tables[0].TableName = "VADBLATT";

            return SResult;
        }
        public DataSet QVAD01(DataRow dwData)
        {
            or1 = OracleDB.CreateCommand();

            or1.CommandText = "SELECT * FROM VADBLATT  "
                    + " WHERE  VADMANDANT=:VADMANDANT: AND VADKOLL=:VADKOLL: AND VADART =:VADART:";
            or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);


            SResult = Connect2Proxy(or1);
            SResult.Tables[0].TableName = "VADBLATT";

            return SResult;
        }
        public void DeleteVADBLATT(DataRow dwData, int option = 1)
        {

            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "DELETE FROM VADBLATT   WHERE  VADMANDANT=:VADMANDANT: AND VADKOLL=:VADKOLL: AND VADART =:VADART:";
                    or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        }

        public void UpdateVADBLATT(DataRow dwData, int option = 1)
        {
            if (option == 0)
            {
                switch (app.company)
                {
                    default:
                    case "JLT":
                        UVAD01(dwData);
                        break;
                }
            }

        }
        public void UVAD01(DataRow dwData)
        {
            or1 = OracleDB.CreateCommand();
            or1.CommandText = "UPDATE VADBLATT SET VADMANDANT=:VADMANDANT:,VADKOLL=:VADKOLL:,VADART=:VADART:,VADSPRKZ=:VADSPRKZ:,VADARTBEZ=:VADARTBEZ:,VADSTDTXT=:VADSTDTXT:,VADPFCODE=:VADPFCODE:,VADETG=:VADETG:,VADSTDART=:VADSTDART:,VADSTDAUF1=:VADSTDAUF1:,VADSTDAUF2=:VADSTDAUF2:,VADSTDAUF3=:VADSTDAUF3:,VADFILLER=:VADFILLER:,VADAENDZL=:VADAENDZL:,VADAENDBEN=:VADAENDBEN:,VADAENDDAT=:VADAENDDAT:,VADNEUBEN=:VADNEUBEN:,VADNEUDAT=:VADNEUDAT:"
                        + " WHERE  VADMANDANT=:VADMANDANT: AND VADKOLL=:VADKOLL: AND VADART =:VADART:";
            or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
            Connect2Proxy(or1);
        }
    }
}
